# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=nextpnr
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.r2859.5e53a182
pkgrel=2
pkgdesc="Portable FPGA place and route tool (mingw-w64)"
arch=('any')
url="https://github.com/YosysHQ/nextpnr"
license=('ISC')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-icestorm"
             "${MINGW_PACKAGE_PREFIX}-openmp"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-qt5"
             "git")

_commit="5e53a18"
source=("${_realname}::git://github.com/YosysHQ/${_realname}.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${_realname}"
  printf "0.0.r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

build() {
  cd "${srcdir}/${_realname}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" cmake \
    -G "MSYS Makefiles" \
    -DICESTORM_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DCMAKE_PREFIX_PATH=${MINGW_PREFIX} \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DARCH='generic;ice40' \
    -DBUILD_HEAP=ON \
    -DUSE_OPENMP=ON \
    -DBUILD_PYTHON=ON \
    -DBUILD_GUI=ON \
    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
    -DBUILD_TESTS=ON \
    .

  cmake --build . --config Release
}

check() {
  cd "${srcdir}/${_realname}"
  make test
}

package() {
  cd "${srcdir}/${_realname}"
  make DESTDIR="${pkgdir}" install

  _licenses="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${_licenses}"
  install -m 644 "${srcdir}/${_realname}"/COPYING "${_licenses}"
}
